<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*, util.db.*" %>
<%

	//用以获取，添加修改学生信息时候，ComboBox中加载数据（班级和年级）
	String cmd = request.getParameter("cmd");
	
	if (cmd != null) {
		if ("getClass".equals(cmd)) {		//加载班级信息
			Connection conn = null;
			PreparedStatement pstmt = null;
			ResultSet rs = null;
			String sql = "select * from t_class order by id";
			//保存返回js数组
			String retStr = "[ ";
			try {
				conn = DBConn.getConn();
				pstmt = DBConn.getPstmt(conn, sql);
				rs = pstmt.executeQuery();
				while (rs.next()) {
					//组装，返回的js数组					
					if (rs.isLast()) {
						retStr = retStr + "['" + rs.getInt("id") + "', '" + rs.getInt("class") + "']";
					} else {
						retStr = retStr + "['" + rs.getInt("id") + "', '" + rs.getInt("class") + "'],";
					}						
				}
				retStr = retStr + " ]";
				out.print(retStr);
			} catch(SQLException e) {
				e.printStackTrace();
			} finally {
				DBConn.close(conn);
				DBConn.close(pstmt);
				DBConn.close(rs);
			}
		} else if ("getGrade".equals(cmd)) {	//加载年级信息
			Connection conn = null;
			PreparedStatement pstmt = null;
			ResultSet rs = null;
			String sql = "select * from t_grade order by id";
			//保存返回js数组
			String retStr = "[ ";
			try {
				conn = DBConn.getConn();
				pstmt = DBConn.getPstmt(conn, sql);
				rs = pstmt.executeQuery();
				while (rs.next()) {
					//组装，返回的js数组					
					if (rs.isLast()) {
						retStr = retStr + "['" + rs.getInt("id") + "', '" + rs.getInt("grade") + "']";
					} else {
						retStr = retStr + "['" + rs.getInt("id") + "', '" + rs.getInt("grade") + "'],";
					}						
				}
				retStr = retStr + " ]";
				out.print(retStr);
			} catch(SQLException e) {
				e.printStackTrace();
			} finally {
				DBConn.close(conn);
				DBConn.close(pstmt);
				DBConn.close(rs);
			}
		}		
	} 
	
%>
